<template>
	<view class="ys">
		<view class="sharbox">
			<view class="title">
				我的邀请码 <image src="../../static/image/fz.svg" @click="copy(code)" mode=""></image>
			</view>
			<view class="code">
				{{code}}
			</view>
			<view class="codeimg">
				<uqrcode ref="uqrcode" canvas-id="qrcode" :value="link" @longtap="save">
				</uqrcode>
			</view>
			<view class="down" @click="saveImg">
				点击保存图片
			</view>
			<view class="title">
				邀请链接 <image src="../../static/image/fz.svg" @click="copy(link)" mode=""></image>
			</view>
			<view class="link">
				{{link}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		UserInfo
	} from "@/api/api.js"
	export default {
		data() {
			return {
				code: '',
				link: ''
			}
		},
		onReady() {
			if (this.$refs.uqrcode) {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {}
				});
			}
		},
		onLoad() {
			this.UserIndex()
		},
		methods: {
			UserIndex() {
				UserInfo().then(res => {
					if (res.code == 0) {
						this.code = res.data.invite_code
						this.link = this.$config.websiteUrl + `pages/register/index?invite=${this.code}`
					}
				})
			},
			saveImg() {
				var that = this
				this.$refs.uqrcode.save({
					success: () => {

					}
				});
			},
			copy(data) {
				uni.setClipboardData({
					data
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		min-height: calc(100vh - 44px);
		/* #ifdef MP-WEIXIN */
		min-height: 100vh;
		/* #endif */
		height: 100%;
		background: #1d3f2b;
		background-size: 100% 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.sharbox {
		width: 280px;
		padding: 18px 0 24px 0;
		background: linear-gradient(0deg, #ffffffb3, #ffffff33);

		display: flex;
		flex-direction: column;
		align-items: center;
		color: #000;
		font-size: 16px;

		.title {
			display: flex;
			font-size: 15px;
			align-items: center;

			.icon {
				margin-left: 5px;
			}

			image {
				width: 15px;
				height: 15px;
				margin-left: 5px;
			}
		}

		.code {
			margin-top: 10px;
			font-weight: bold;
		}

		.down {
			margin: 15px 0;
		}

		.codeimg {
			width: 80%;
			margin-top: 10px;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 100%;
			}
		}

		.link {
			margin-top: 10px;
			width: 80%;
			word-break: break-all;
			font-size: 13px;
		}

	}
</style>